import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)
// vuex 的数据刷新会丢失
// 创建vuex对象
const store = new Vuex.Store({
  state: {
    count: 1 // 计数器
  },
  mutations: {
    changeCount (state, num) {
      state.count += num
    }
  },
  actions: {
    countAct ({ commit }, num) {
      commit('changeCount', num)
    }
  },
  modules: {
    app,
    settings,
    user
  },
  getters,
  plugins: [createPersistedState()] // 使用插件 让vuex持久化
})

export default store
